#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python
import os, sys

progname = os.path.splitext( os.path.basename(sys.argv[0]) )[0]
print 'execute: ', progname


argn = len(sys.argv)
if argn<2 :
    print "X . X . X . X"
    print ">> Type the source.txt, which is located ~/Downloads"
    print 
    exit(1)

LEVEL = 0

if argn>2 :
    LEVEL = int ( sys.argv[2] )

if LEVEL < 2:
    soufn = sys.argv[1]
    sf = "/Users/jhy/Downloads/%s"%( soufn )
    if not os.path.exists(sf) :
        print ">> Could not find the file: ", sf
        exit(1)

    # move file to local
    cmd = 'mv %s %s.txt; rm -f %s*.txt'%(sf, progname, sf.split('.')[0] )
    print cmd
    os.system(cmd)

    # convert txt to cpp
    cmd = 'cat %s.txt > %s.cpp' % (progname, progname)
    print cmd
    os.system(cmd)

# compile
cmd = 'g++ %s.cpp -o %s.exe' % (progname, progname)
print cmd
os.system(cmd)

# run
cmd = './%s.exe'%(progname)
print cmd
os.system(cmd)


